/**
 * 
 */
package hr.mlab.app.expenses;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import android.content.Context;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;

/**
 * @author zalhaj
 *
 */
public  class DbInitialization {
	

     
	 public static void  Initdata (Context context, SQLiteDatabase db) {
		 String statement;
 
		 try {
            Toast.makeText( context, "Initialising database", 2000).show();
            InputStream in = context.getResources().openRawResource(R.raw.sql);
            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder.parse(in, null);
            NodeList statements = doc.getElementsByTagName("statement");
            for (int i=0; i<statements.getLength(); i++) {
                    statement = statements.item(i).getChildNodes().item(0).getNodeValue();
                    db.execSQL(statement);
            }
		 } catch (Throwable t) {
            Toast.makeText(context, t.toString(), 50000).show();
		 }
	 }
}
